import {DynamicTable} from "./index.vue.d";
import {CreateElement} from "vue/types/vue";
import {TableColumn} from "element-ui";
import {VNode} from "vue";

export class TableConfig { // 直接使用el-table所有配置
  tableItems: TableItemConfig[] = []
  events: { [find: string]: Function } = {} // 记录事件
  /**
   *
   * @param self
   * @param items
   */
  constructor(self: DynamicTable, items: TableItemConfig[]) {
    Object.keys(self).forEach(key => {
      this[key] = self[key]
    })
    this.tableItems = items
  }
}

export class TableItemConfig implements TableColumn {
  children: TableItemConfig[] = [] // 子项
  slotName?: string;
  prop: string;
  /**
   * 组件插槽
   * @param h
   * @param item
   */
  typeSlots?(h: CreateElement, item: TableItemConfig): { [key: string]: VNode[] } {
    return {}
  }

  hidden: boolean = false
  // @ts-ignore
  formatter?(row: object, column: TableColumn,cellValue:any, index:number):string {return ''};
  params?: {[key: string]:any}; // 存放额外的参数
}

export class SelectConfig implements TableColumn {
  /**
   *
   * @param self
   */
  constructor(self: SelectConfig) {
    Object.keys(self).forEach(key => {
      this[key] = self[key]
    })
  }
}
